<template>
	<view>
		<view class="m-top">
			<navigator class="m-top-nav" url="./meishi"></navigator>
			<view class="m-top-text">套餐列表</view>
			<navigator class="input-wrap" url="/pages/shop_new/search/search"><input type="text" value="" placeholder="冷面 麻辣烫" /></navigator>
		</view>
		<view class="m-info-bg">
			<view class="m-today-wrap" v-if="taocanList.length">
				<view class="m-today-info">
					<view class="m-today-item" v-for="(item,index) in taocanList" :key="index">
						<image class="m-today-item-img" :src="item.goods[0]['image']"></image>
						<view class="m-today-item-info">
							<view class="m-today-item-text">{{ item.name }}</view>
							<view class="m-today-item-store">{{ item.store_name }}</view>
							<view class="m-today-item-price-wrap">
								<view class="m-today-item-price">
									<view class="m-today-item-price-new">
										<span>￥</span>
										<span>{{item.price}}</span>
									</view>
									<view class="m-today-item-price-old" v-if="item.old_price > item.price">
										<span>￥</span>
										<span>{{item.old_price}}</span>
									</view>
								</view>
								<view class="m-today-item-btn" @click="toTaocanDetail(item['goods'][0])">购买</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import common from '../../../utils/common.js'
export default {
	data() {
		return {
			taocanList:[],
			delivery_address: '',
			isShowAll: false,
			subNavListAll: [],
			subNavList: [],
			nearByData: [],
			mZhongHe: true,
			showFilterMask: false,
			nav_0: true,
			nav_1: true,
			nav_2: true,
			nav_3: true
		}
	},
	onLoad(options) {
		const { cat_id, cat_url } = options
		this.getTakeoutSecTypesByFid(cat_id)
		this.getShopList(cat_url)
		this.getTaocan()
	},
	mounted() {},
	methods: {
		toTaocanDetail(item){
			const { store_id,goods_id } = item
			// console.log(store_id,goods_id)
			const url = `../goodsDetail/goodsDetail?store_id=${store_id}&product_id=${goods_id}`
			uni.navigateTo({
			    url: url
			});
		},
		getTaocan(){
			var param = {}
			common.post('Shop_new&a=mTaocan', param, data => {
				// console.log('套餐', data)
				this.taocanList = data
			})
		},
		getShopList(cat_url) {
			var param = {
				cat_url
			}
			common.post('Shop_new&a=ajax_list', param, data => {
				console.log('店铺列表', data)
				this.nearByData = data.store_list
			})
		},
		navShowAllFn() {
			this.isShowAll = true
			this.subNavList = this.subNavListAll
		},
		getTakeoutSecTypesByFid(cat_id) {
			var param = {
				cat_id
			}
			common.post('Shop_new&a=mTakeoutSecTypesByFid', param, data => {
				this.subNavListAll = data
				this.subNavList = data.slice(0, 4)
			})
		},
		filterByDeliveryType() {
			// 兔兔叮配送
			let data = this.nearByData
			data = data.filter(item => item.deliver_name === '兔兔叮配送')
			this.nav_0 = false
			this.nav_1 = false
			this.nav_2 = false
			this.nav_3 = true
			this.showFilterMask = false
			this.nearByData = data
		},
		filterByDeliveryFree() {
			// 免费配送
			let data = this.nearByData
			data = data.filter(item => item.deliver_discount.type === 'deliver_free')
			this.nav_0 = false
			this.nav_1 = false
			this.nav_2 = false
			this.nav_3 = true
			this.showFilterMask = false
			this.nearByData = data
		},
		sortBySale() {
			// 销量最高
			let data = this.nearByData
			data = data.sort(function(a, b) {
				return parseFloat(a.month_sale_count) - parseFloat(b.month_sale_count)
			})
			this.nav_0 = true
			this.nav_1 = false
			this.nav_2 = false
			this.nav_3 = false
			this.showFilterMask = false
			this.nearByData = data
		},
		sortByScore() {
			// 评分最高
			let data = this.nearByData
			data = data.sort(function(a, b) {
				return parseFloat(a.star) - parseFloat(b.star)
			})
			this.nav_0 = true
			this.nav_1 = false
			this.nav_2 = false
			this.nav_3 = false
			this.showFilterMask = false
			this.nearByData = data
		},
		sortByDeliveryTime() {
			// 配送时间
			let data = this.nearByData
			data = data.sort(function(a, b) {
				return parseFloat(a.delivery_time) - parseFloat(b.delivery_time)
			})
			this.nav_0 = false
			this.nav_1 = false
			this.nav_2 = true
			this.nav_3 = false
			this.nearByData = data
		},
		sortByDistance() {
			// 离我最近
			let data = this.nearByData
			data = data.sort(function(a, b) {
				return parseFloat(a.range) - parseFloat(b.range)
			})
			this.nav_0 = false
			this.nav_1 = true
			this.nav_2 = false
			this.nav_3 = false
			this.nearByData = data
		},
		showFilterMaskFn(num) {
			// uni.pageScrollTo({
			// 	scrollTop: 0,
			// 	duration: 100,
			// })
			if (num) {
				this.mZhongHe = false
				this.nav_0 = false
				this.nav_3 = true
			} else {
				this.mZhongHe = true
				this.nav_0 = true
				this.nav_3 = false
			}
			this.nav_1 = false
			this.nav_2 = false
			this.showFilterMask = true
		}
	}
}
</script>

<style lang="scss">
@import '../take-out/takeout.scss';
@import './meishi.scss';
</style>
